﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exdot
{
    public class Statictis
    {
        QuanLyChiTieuEntities context = new QuanLyChiTieuEntities();
        public object thongKeShow()
        {
            //object kq = new object();
            //var query = from tn in context.ThuNhaps
            //            join ct in context.ChiTieux on tn.MaThuNhap equals ct.MaChiTieu
            //            select new { tn.TenTN, SoTienTN=tn.SoTien, ThoiGianTN=tn.ThoiGian, ct.TenChiTieu,SoTienCT=ct.SoTien,ThoiGianCT=ct.ThoiGian};
            //kq = query.ToList();
            //return kq;
            object kq = new object();
            var query = from tn in context.ThuNhaps
                        group tn by tn.ThoiGian.Month into g
                        select new { TongThuNhap = g.Sum(p => p.SoTien), ThoiGianTN = g.Key };
            var query1 = from ct in context.ChiTieux
                         group ct by ct.ThoiGian.Month into g
                         select new { TongChiTieu = g.Sum(p => p.SoTien), ThoiGianCT = g.Key };
           // var query2 = from tn in query join ct in query1 on tn.ThoiGianTN equals ct.ThoiGianCT select new { tn.ThoiGianTN, tn.TongThuNhap, ct.TongChiTieu };
            KeyValuePair<double, int> tempk = new KeyValuePair<double, int>(0, 0);
            var query3 = (from tn in query join ct in query1 on tn.ThoiGianTN equals ct.ThoiGianCT into gj from subpet in gj.DefaultIfEmpty() select new { Thang = tn.ThoiGianTN, tn.TongThuNhap, TongChiTieu = (subpet.TongChiTieu == null ? 0 : subpet.TongChiTieu) });
            var query2 = (from ct in query1 join tn in query on ct.ThoiGianCT equals tn.ThoiGianTN into gj from subpet in gj.DefaultIfEmpty() select new { Thang = ct.ThoiGianCT, TongThuNhap = (subpet.TongThuNhap == null ? 0 : subpet.TongThuNhap), ct.TongChiTieu });
            kq = query3.ToList();
            return kq;
        }
    }
}
